package com.epam.DAO.JPA;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import com.epam.DAO.ClientDAO;
import com.epam.entity.Client;

public class ClientDAOJPA extends GenericDAOJPA<Client> implements ClientDAO{

	public ClientDAOJPA() {
		super(Client.class);
	}
		
	@Override
	public Client read(String login, String pass) {

		Client client;
		EntityManager em = getEntityManager();
		TypedQuery<Client> query = em.createQuery(
				"SELECT c FROM Client c WHERE c.user.login = :login AND c.user.pass = :pass", Client.class);
		query.setParameter("login", login);
		query.setParameter("pass", pass);
		client = query.getResultList().get(0);
		em.close();
		return client;
	}
	
}
